package com.nacol.demo.gateway.loadbalance;

import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author Nacol(姚秋实)
 * @Date 2023/12/11
 * @Title 自定义负载均衡配置
 */
@Configuration
public class CustomLoadBalancerConfiguraiton {

    /** customer服务名称，可从配置中获取，因demo演示此处写死 */
    private final String CUSTOMER_ID = "customer";

    /**
     * @Author Nacol(姚秋实)
     * @Date 2023/12/11
     * @Title 重写【Customer】服务的负载均衡策略
     */
    @Bean
    public ReactorServiceInstanceLoadBalancer customLoadBalancer(LoadBalancerClientFactory loadBalancerClientFactory) {
        return new NearlyLoadBalancer(CUSTOMER_ID, loadBalancerClientFactory);
    }


}
